/*! \file OrbitFunctors.cpp
 *	\brief 
 *
 *	created:	2010/09/08
 *	created:	8:9:2010   12:15
 *	filename: 	s:\DNG-Code\Kiev\Modules\Orbit\Protection\Source\Common\OrbitFunctors.cpp
 *	file path:	s:\DNG-Code\Kiev\Modules\Orbit\Protection\Source\Common
 *	file base:	OrbitFunctors
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
#include "core/stdafx.h"
#include "Functors.h"

#if defined(TT_UNIX)
#include <string.h> //memcmd
#endif //defined(TT_UNIX)

namespace tt{
namespace core{

bool operator==(const FunctorBase &lhs,const FunctorBase &rhs)
{
	if(!lhs.target)
	{
		if(rhs.target)
			return false;
		return lhs.func == rhs.func;
	}
	else
	{
		if(!rhs.target)
			return false;
		return lhs.target == rhs.target &&
			!memcmp(lhs.memFunc,rhs.memFunc,FunctorBase::MEM_FUNC_SIZE);
	}
}

bool operator!=(const FunctorBase &lhs,const FunctorBase &rhs)
{
	return !operator==(lhs,rhs);
}

bool operator<(const FunctorBase &lhs,const FunctorBase &rhs)
{
	//must order across funcs and target/memfuncs, funcs are first
	if(!lhs.target)
	{
		if(rhs.target)
			return true;
		else
			return lhs.func < rhs.func;
	}
	else
	{
		if(!rhs.target)
			return false;
		if(lhs.target != rhs.target)
			return lhs.target < rhs.target;
		else
			return memcmp(lhs.memFunc,rhs.memFunc,FunctorBase::MEM_FUNC_SIZE) < 0;
	}
}

} //namespace core
} //namespace tt

